package com.company.Sort2;

import jdk.nashorn.tools.Shell;

import java.util.Arrays;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}10:55
 */
public class ShellSort {
    public static void main(String[] args) {
        int[] arr = {1,15,58,-1,2};
        System.out.println(Arrays.toString(Shells(arr)));
    }

    public static int[] Shells(int[] arr){
        //得到每次分化的单位数
        for (int i = arr.length/2; i > 0; i = i / 2){//规定分化的循环 i为分化的单位量
            //使用位移法 插入排序那种
            for (int j = i;j<arr.length;j++) {
                int index = j;
                int temp = arr[index];
                if (arr[index] < arr[index - i]){
                    while (index - i > 0 && temp < arr[index - i]){
                        arr[index] = arr[index - i];
                        index = index - i;
                    }
                    arr[index] = temp;
                }
            }
        }
        return arr;
    }
}
